// pages/setUp/shopAuthen/shopAuthen.js
var timer = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    disable: false,
    time: '获取验证码',
    currentTime: 60,
    cardFontImg: '',
    cardBackImg: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 验证码
  getCode: function () {
    var that = this;
    var currentTime = that.data.currentTime
    that.setData({
      disable: true,
      time: currentTime + '秒'
    })
    timer = setInterval(function () {
      currentTime--;
      that.setData({
        time: currentTime + '秒'
      })
      if (currentTime <= 0) {
        clearInterval(timer);
        that.setData({
          time: '重新发送',
          currentTime: 60,
          disable: false
        })
      }
    }, 1000)
  },
  // 上传身份证
  getCard: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        that.setData({
          cardFontImg: tempFilePaths[0]
        })
      }
    })
  },
  getCardBack: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        that.setData({
          cardBackImg: tempFilePaths[0]
        })
      }
    })
  },
})